#include <mFS/FsTypes.h>
#include <mFS/mConfig.h>
#include <Utils/Mem.h>
#include <apdu/APDUParse.h>
#include <apdu/SwCode.h>
#include <apdu/CryptRandomAP.h>
#include <cmd/CMDCryptRandom.h>


void CMDCryptRandom_GetRealRandom(void)
{
	ApduCmd *pCmd;
	ApduRsp *pRsp;
	UINT16 nRet;

	pCmd = APDU_GetCmd();
	pRsp = APDU_GetRsp();

	if(pCmd->CLA != 0x80)
	{
		APDU_SetRespond(0, ISOSW_CLA_ERROR);
		return ;
	}

	if(pCmd->LE > CONFIG_MAX_DATA_LEN)
	{
		APDU_SetRespond(0, ISOSW_LE_ERROR | 255);
		return ;
	}

	if(pCmd->P1 > 1 || pCmd->P2 != 0)
	{
		APDU_SetRespond(0, ISOSW_P1P2_ERROR);
		return ;
	}

	nRet = CryptRandomAP_GetRealRandom(pCmd->P1, pRsp->pData, pCmd->LE);

	APDU_SetRespond(pCmd->LE, nRet);

	return ;
}
